from torch.utils.tensorboard import SummaryWriter
from PIL import Image
from torchvision import transforms

writer = SummaryWriter("log")
img = Image.open("dataset/train/bees/85112639_6e860b0469.jpg")

#ToTensor的使用
trans_totensor = transforms.ToTensor()
img_tensor = trans_totensor(img)
writer.add_image("Image_tensor",img_tensor)


#Normalize
trans_norm = transforms.Normalize([0.5,0.5,0.5],[1,1,1])
img_norm = trans_norm(img_tensor)
writer.add_image("Normalize",img_norm)


#Resize
trans_resize = transforms.Resize((512,512))
print(img)
img_resize = trans_resize(img)
print(img_resize)
img_resize = trans_totensor(img_resize)
print(type(img_resize))
writer.add_image("Resize",img_resize)

#Compose
trans_resize2 = transforms.Resize(256)
trans_com = transforms.Compose([trans_resize2,trans_totensor])
img_resize2 = trans_com(img)
print(type(img_resize2))
writer.add_image("Compose",img_resize2,1)

#RandomCrop
trans_rp = transforms.RandomCrop(128)
trans_compose2 = transforms.Compose([trans_rp,trans_totensor])
for i in range(10):
    img_rand = trans_compose2(img)
    writer.add_image("RandomCrop",img_rand,i)
writer.close()

